package com.team.star.controller;

import com.team.star.entity.vo.ChatMessageVO;
import com.team.star.utils.ResponseCode;
import com.team.star.utils.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.client.advisor.AbstractChatMemoryAdvisor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;

@Tag(name = "AiChatController")
@RestController
@CrossOrigin("*")
public class AiChatController {
    private final ChatClient chatClient;

    @Autowired
    public AiChatController(ChatClient chatClientBuilder) {
        this.chatClient = chatClientBuilder;
    }


    @Operation(summary = "普通对话")
    @PostMapping(value = "/chatAll")
    public Result<String> generateResponseAll(@RequestBody ChatMessageVO chatMessageVO) {
        String content = this.chatClient.prompt()
                .user(chatMessageVO.getMessage())
                .system(promptSystemSpec ->
                        promptSystemSpec.param("currentDate", LocalDate.now().toString()))
                .advisors(advisorSpec -> advisorSpec.param(AbstractChatMemoryAdvisor.CHAT_MEMORY_RETRIEVE_SIZE_KEY, 30))
                .call()
                .content();
        return Result.success(ResponseCode.SUCCESS, content);
    }

}
